package com.igeekhome.controller;

import com.igeekhome.dto.ReceiveAndDestDto;
import com.igeekhome.dto.SectionDestDto;
import com.igeekhome.dto.SectionNetworkDto;
import com.igeekhome.service.IDestService;
import com.igeekhome.service.INetworkService;
import com.igeekhome.service.ISendingMainListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 立以宁
 */
@Controller
@RequestMapping("/page/")
public class SendingSectionController {

    @Autowired
    private ISendingMainListService sendingMainListService;

    @Autowired
    private INetworkService networkService;

    @Autowired
    private IDestService destService;

    /**
     * 区间维护的界面
     * @return
     */
    @RequestMapping("/sectionList")
    public String sectionList() {
        return "/pages/data/quote/sectionMaintain";
    }

    @RequestMapping("/sectionAdd")
    public String sectionAdd() {

        return "/pages/data/quote/sectionAdd";
    }

    @RequestMapping("/sectionUpdate/{id}")
    public String sectionUpdate(@PathVariable Integer id,Model model) {
        ReceiveAndDestDto receiveAndDestDto = sendingMainListService.selectById(id);
        if (receiveAndDestDto!=null) {
            model.addAttribute("DSendingMaintenanceList",receiveAndDestDto.getDSendingMaintenanceList());
            model.addAttribute("StrId",receiveAndDestDto.getStrId());
            model.addAttribute("Str",receiveAndDestDto.getStr());
            model.addAttribute("id",id);
        }
        return "/pages/data/quote/sectionAdd";
    }

    @RequestMapping("/sectionTree/{idx}/{id}")
    public String selectSection(@PathVariable Integer id,String strId,Model model,@PathVariable Integer idx) {
        System.out.println("idx："+idx);
     /*if (id == 0 && strId !=null) {
         List<SectionNetworkDto> sectionNetworkDtos = networkService.selectNetworkInIds(strId);
         model.addAttribute("list",sectionNetworkDtos);
     } else if (id == 1 && strId !=null){
         List<SectionDestDto> sectionDestDtos = destService.selectDestInIds(strId);
         model.addAttribute("list",sectionDestDtos);
     }*/

        model.addAttribute("id",id);
        model.addAttribute("list",strId);
        model.addAttribute("idx",idx);

        return "/pages/data/quote/selectSection";
    }


}
